import 'dart:convert';

import 'package:base_flutter/base_flutter.dart';
import 'package:ls_work/net/api/meter_reading_api.dart';
import 'package:ls_work/net/post_request.dart';

import '../net/response/room_list_data.dart';

class MeterReadingModel extends BaseMvvmModel {
  @override
  void onCleared() {}

  Future<List<RoomListData>> getMeterRoomList(
      String buildingId, String floorId,{dynamic type}) async {
    var map = {
      "buildingId": buildingId,
      "floorId": floorId,
      "type":type
    };
    var data =
        await HttpGo.instance.postData(MeterReadingApi.roomList, data: map);
    if ("0" == data['code']) {
      var list = ((data['data']['list'] as List) ?? [])
          .map((e) => RoomListData.fromJson(e))
          .toList();
      return list;
    } else {
      throw data['msg'];
    }
  }

  ///提交抄表
  Future<Map> submitMeterReading(List<Map> meterList) async {
    var map = {"recordJson": meterList};
    var data = await HttpGo.instance.postData(
        MeterReadingApi.submitMeterReading,
        data: map,);
    if ("0" == data['code']) {
      return map;
    } else {
      throw data['msg'];
    }
  }
}
